import ElementUI from 'element-ui';
import { sendMsg2main } from './utils/mixin';

// 监听内部dialog显示隐藏
const oldVisible = ElementUI.Dialog.watch.visible;
ElementUI.Dialog.watch.visible = {
  handler(val) {
    sendMsg2main({ type: !val ? "cancelIframeCover" : "setIframeCover" });
    // setTimeout(() => {
    oldVisible.call(this, val);
    // });
  },
  // immediate: true,
};

// dialog使用了v-if导致第一次显示时，无法触发visible的监听
const oldCreated = ElementUI.Dialog.mounted;
ElementUI.Dialog.mounted = function () {
  if (this.$options.propsData.visible) {
    sendMsg2main({ type: "setIframeCover" });
  }
  oldCreated.call(this);
};

// dialog使用了v-if导致卸载时，无法触发visible的监听
const oldDestroyed = ElementUI.Dialog.destroyed;
ElementUI.Dialog.destroyed = function () {
  sendMsg2main({ type: "cancelIframeCover" });
  oldDestroyed.call(this);
};